package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.BusinessCategoryModel;

import java.util.List;

/**
 * Created by Raven on 2017/12/13.
 */

public class BusinessCateSelectAdapter extends BaseRecyclerAdapter<BusinessCategoryModel.BusinessChildCate,BusinessCateSelectAdapter . BusinessCateSelectHolder>{

    private int mSelectedPosition = -1;

    public BusinessCateSelectAdapter(Context context, List<BusinessCategoryModel.BusinessChildCate> data) {
        super(context, data);
    }

    @Override
    public void onBindViewHolder(BusinessCateSelectHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(position);

    }

    @Override
    public BusinessCateSelectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BusinessCateSelectHolder(layoutInflater.inflate(R.layout.item_business_child_cate, parent, false));
    }

    public class BusinessCateSelectHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView itemTvBusinessCateName;

        public BusinessCateSelectHolder(View itemView) {
            super(itemView);
            itemTvBusinessCateName = (TextView) itemView.findViewById(R.id.item_tv_business_cate_name);
        }

        public void bindData(int position) {
            itemTvBusinessCateName.setSelected(position == mSelectedPosition);
            itemTvBusinessCateName.setText(data.get(position).getServiceName());
        }
    }

    public void setSelectedPosition(int position){
        mSelectedPosition = position;
        notifyDataSetChanged();
    }

    public int getSelectedPosition(){
       return  mSelectedPosition;
    }
}
